﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Web_viewinfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["typeid"] != null && Session["tid"] != null)
            {
                this.labTime.Text = DateTime.Now.ToString();
                string typeid = Session["typeid"].ToString().Trim();//可以是Session值，在main中或default中生成
                int usertype =Int32.Parse(Session["UserType"].ToString().Trim());
                string tid = Session["tid"].ToString().Trim();
                if (typeid != "99")
                    GetAllInfo(typeid, usertype, tid);
                else
                {
                    if (Session["UserType"].ToString().Trim() == "4")
                        Response.Redirect("adminview.aspx");
                    GetAllInfo1(typeid, usertype, tid);//仅供浏览
                    if (usertype == 3)
                        GetFields(tid);
                }
                //获取时间
                getTime();
                //获取身份
                this.labAccount.Text = GetIdentity(usertype.ToString());
                //获取新闻和项目消息
                getPNInfo();
                //获取所有项目以及个人数据
                HideDiv(usertype, typeid);
                PM.PMBasic.Mail Mail = new PM.PMBasic.Mail();
                this.hlUnRead.Text = Mail.GetUnread(tid).ToString();
            }
        }
    }

    protected void getTime()
    {
        DateTime NowTime = DateTime.Now;
        StringBuilder timestr = new StringBuilder();
        timestr.Append(NowTime.Year.ToString()).Append(",").Append((NowTime.Month-1).ToString()).Append(",").Append(NowTime.Day.ToString());
        timestr.Append(",").Append(NowTime.Hour.ToString()).Append(",").Append(NowTime.Minute.ToString()).Append(",").Append(NowTime.Second.ToString());
        this.HiddenField1.Value = timestr.ToString();
    }

    protected void getPNInfo()
    {
        StringBuilder projectnews = new StringBuilder(" ");
        StringBuilder mininews = new StringBuilder(" ");
        PM.PMSys.news pn = new PM.PMSys.news();
        pn.CreateMiniNews(ref projectnews,ref mininews);
        this.project.InnerHtml = projectnews.ToString();
        this.news.InnerHtml = mininews.ToString();
    }

    protected void HideDiv(int identitytype,string typeid1)
    {
          if (identitytype == 1||typeid1!="99")
          {
              Panel1.Visible = true;
              Panel2.Visible = false;
          }
          else
          {
              Panel1.Visible = false;
              Panel2.Visible = true;
              if (identitytype == 3)
                  this.labOrient.Text = "项目";
          }
    }
    //获取身份
    protected string GetIdentity(string typeid)
    {
        try
        {
            string sqlstr = "select typename from Sys_UserType where typeid='"+typeid+"'";
            return PM.Code.DAL.DbHelper.GetSingle(sqlstr).ToString();
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
    //项目管理员：获取负责的项目
    protected void GetFields(string tid1)
    {
        StringBuilder result = new StringBuilder("："); 
        string sqlstr = "select btnname from dbo.Sys_Guide where inchargeid='" + tid1 + "'";
        SqlDataReader reader = PM.Code.DAL.DbHelper.ExecuteDataReaderBySql(sqlstr);
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                result.Append(reader[0].ToString().Trim()).Append("，");
            }
        }
        reader.Close();
        this.labCollege.Text = result.ToString();
    }
    //表示在申请项目状态
    protected void GetAllInfo(string typeid1,int usertype1,string tid1)
    {
        try
        {
            SqlParameter[] InfoParameter ={ 
                new SqlParameter("@usertype",SqlDbType.TinyInt),
                new SqlParameter("@typeid",SqlDbType.Int),
                new SqlParameter("@tid",SqlDbType.NVarChar,50)};
            InfoParameter[0].Value = usertype1;
            InfoParameter[1].Value = typeid1;
            InfoParameter[2].Value = tid1;
            SqlDataReader reader = PM.Code.DAL.DbHelper.RunProcedure("Pdmis_GetViewInfo", InfoParameter);
            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    this.labCollege1.Text = reader[1].ToString();//所在学院
                    this.labTname.Text = reader[2].ToString();//学院管理员：名字
                    this.labCell.Text = reader[3].ToString();//学院管理员：手机
                    this.labTel.Text = reader[4].ToString();//学院管理员：电话
                    this.labEmail.Text = reader[5].ToString();//学院管理员：邮箱
                    this.labType.Text = reader[6].ToString();//所申报的项目的类型
                    this.labTname1.Text = reader[7].ToString();//项目管理员：姓名
                    this.labCell1.Text = reader[8].ToString();//项目管理员：手机
                    this.labTel1.Text = reader[9].ToString();//项目管理员：电话
                    this.labMail.Text = reader[10].ToString();//项目管理员：邮箱
                    this.labBC.Text = reader[11].ToString();//已经保存
                    this.labDSP.Text = reader[12].ToString();//待审批
                    this.labTHXG.Text = reader[13].ToString();//退回修改
                    this.labSCTG.Text = reader[14].ToString();//初审通过
                    this.labTJ.Text = reader[15].ToString();//已提交
                    this.labLX.Text = reader[16].ToString();//已立项
                }
                reader.Close();
            }
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
    //typeid==99表示仅是浏览状态
    protected void GetAllInfo1(string typeid1, int usertype1, string tid1)
    {
        try
        {
            SqlParameter[] InfoParameter ={ 
                new SqlParameter("@usertype",SqlDbType.TinyInt),
                new SqlParameter("@typeid",SqlDbType.Int),
                new SqlParameter("@tid",SqlDbType.NVarChar,50)};
            InfoParameter[0].Value = usertype1;
            InfoParameter[1].Value = typeid1;
            InfoParameter[2].Value = tid1;
            SqlDataReader reader = PM.Code.DAL.DbHelper.RunProcedure("Pdmis_GetViewInfo", InfoParameter);
            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    if (usertype1 == 1)
                    {
                        this.labCollege1.Text = reader["depart"].ToString();//所在学院
                        this.labTname.Text = reader["name"].ToString();//学院管理员：名字
                        this.labCell.Text = reader["cellphone"].ToString();//学院管理员：手机
                        this.labTel.Text = reader["telephone"].ToString();//学院管理员：电话
                        this.labEmail.Text = reader["email"].ToString();//学院管理员：邮箱
                    }
                    else if (usertype1 == 2)
                    {
                        this.labCollege.Text = reader["depart"].ToString();
                        this.labApprove.Text = reader["work"].ToString();
                        this.labNApprove.Text = reader["undone"].ToString();
                    }
                    else if (usertype1 == 3)
                    {
                        this.labApprove.Text = reader["work"].ToString();
                        this.labNApprove.Text = reader["undone"].ToString();
                    }
                    this.labTname1.Text = reader["name1"].ToString();//系统管理员：姓名
                    this.labCell1.Text = reader["cellphone1"].ToString();//系统管理员：手机
                    this.labTel1.Text = reader["telephone1"].ToString();//系统管理员：电话
                    this.labMail.Text = reader["email1"].ToString();//系统管理员：邮箱
                    this.labBC.Text = reader["BC"].ToString();//已经保存
                    this.labDSP.Text = reader["DSP"].ToString();//待审批
                    this.labTHXG.Text = reader["TH"].ToString();//退回修改
                    this.labSCTG.Text = reader["SCTG"].ToString();//初审通过
                    this.labTJ.Text = reader["YTJ"].ToString();//已提交
                    this.labLX.Text = reader["YLX"].ToString();//已立项
                }
                reader.Close();
                this.labNote.Text = "有问题请联系本系统管理员";
            }
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
}
